angular.module('starter')
  .config(function($stateProvider) {
    $stateProvider.state('addTable4', {
      url: '/addTable4/:tableId',
      templateUrl: 'templates/addTable4/addTable4.html',
      controller: 'addTable4Ctrl',
      controllerAs: 'addTable4Ctrl'
    })
  })
  .controller('addTable4Ctrl', function($scope,$http) {
    var _this = $scope;
    var _writeDate = $scope.dateToStr(new Date,'yyyy-MM-dd');

    this.data = {
      pageNum: "123",
      tableType: 4, // 表格类型
      layerType: "1", // 面层类型1 2 3 
      recordNo: "1234", // 编号
      workTime: "", // 施工日期str
      workTimeDate:null,// 施工日期Date
      writeDate:_writeDate, // 填表日期
      defectIshandled: 1, // 下承层缺陷是否处理完毕 
      status: 1, // 状态:0:草稿;1:新增
      postil: "批注批注批注批注批注", // 批注
      workPoint: "1", // 作业点
      startStake:"1",//起始桩号
      startStakeFirst:1,
      startStakeLast:3,
      endStakeFirst:3,//截止桩号
      endStakeLast:3,
      checkItemMap: {
        subLayerHasUnconformityAggregate: [{ // 检查项键           
          stakeFirst:1,
          stakeLast:1,
          result: 1, // 结果
        }],
        subLayerGlassGridIsFloating: [{
          stakeFirst:1,
          stakeLast:1,
          result: 1, // 结果
        }],
        subLayerHasPeelingAndPitchIsInPlace: [{
          stakeFirst:1,
          stakeLast:1,
          result: 1, // 结果
        }],
        subLayerCurbStoneSideHasSprayPitchAndHeightUnanimous: [{
          stakeFirst:1,
          stakeLast:1,
          result: 1, // 结果
        }],
        subLayerConstructionSurfaceAndBridgeWaterproofQuality: [{
          stakeFirst:1,
          stakeLast:1,
          result: 1, // 结果
        }]
      }
    };

    this.checkItem = function(){
      if(this.data.workTimeDate) {
          this.data.workTime = $scope.dateToStr(this.data.workTimeDate,'yyyy-MM-dd');    
      }
      return true;
    }

    this.saveTable = function() {
      if(this.checkItem()){
         this.data.status = 0;
         $http.post("qss/form/addForm",this.data).success(function(res){

          _this.showAlert(res.message);
          if(res.success) {
          
          }
         });
      }
    };

    this.submitTable = function() {
      if(this.checkItem()){
         this.data.status = 1;
         $http.post("qss/form/submitForm",this.data).success(function(res){
            console.log(res);
         });
      }
    };

    this.cancle = function() {

    };

  });